package com.blog.cloud.chat.controller;

import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

@Controller
public class WebSocketController {

    // 当客户端发送 /app/sendMessage 路径的消息时，这个方法会被调用
    @MessageMapping("/sendMessage")
    // 处理完消息后，将消息发送到 /topic/messages 路径，所有订阅了这个路径的客户端都将收到消息
    @SendTo("/topic/messages")
    public String sendMessage(String message) {
        System.out.println("Received: " + message);
        return "Received: " + message;
    }
}
